﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Codejam2014.R1B
{
    class Program
    {
        class Sample
        {
            public int a;
            public int b;
            public int k;
        }

        static void Main(string[] args)
        {
            string sampleName = "small1";
            string sampleDir = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory))) + "\\";
            string iFilePath = sampleDir + sampleName + ".i.txt";
            string oFilePath = sampleDir + sampleName + ".o.txt";
            string cFilePath = sampleDir + sampleName + ".c.txt";

            string[] iLines = File.ReadAllLines(iFilePath);
            List<string> oLines = new List<string>();

            int lineCnt = 0;
            int sampleCnt = int.Parse(iLines[lineCnt++]);

            List<Sample> sampleList = new List<Sample>();
            for (int sampleIdx = 0; sampleIdx < sampleCnt; sampleIdx++)
            {

                string[] itemList = iLines[lineCnt++].Split(new char[] { ' ' });

                Sample s = new Sample();
                s.a = int.Parse(itemList[0]);
                s.b = int.Parse(itemList[1]);
                s.k = int.Parse(itemList[2]);
                sampleList.Add(s);
            }

            for (int sampleIdx = 0; sampleIdx < sampleCnt; sampleIdx++)
            {
                Sample s = sampleList[sampleIdx];

                int sum = 0;
                for (int i = 0; i < s.a ; i++)
                {
                    for (int j = 0; j < s.b; j++)
                    {
                        int r = i & j;
                        if ( r < s.k ) sum++;
                    }
                }
                oLines.Add(string.Format("Case #{0}: {1}", sampleIdx + 1, sum));
            }
            File.WriteAllLines(oFilePath, oLines);

            if (File.Exists(cFilePath))
            {
                string[] cLines = File.ReadAllLines(cFilePath);
                for (int sampleIdx = 0; sampleIdx < sampleCnt; sampleIdx++)
                {
                    string oLine = oLines[sampleIdx];
                    string cLine = cLines[sampleIdx];

                    if (oLine != cLine)
                    {
                        throw new Exception("not match");
                    }
                }
            }
        }
    }
}
